package com.example.demo.bizhan.reflect;

import org.junit.Test;

import java.lang.reflect.Constructor;

import static java.lang.System.*;

/**
 * @description: xxx
 * @time: 2020-10-26 22:33
 * @author: baojinlong
 **/
public class ConstructDemoTest {

    @Test
    public void test02() throws Exception {
        Class<?> studentClazz = Class.forName("com.example.demo.bizhan.reflect.Student");
        Constructor<?> constructor = studentClazz.getConstructor(String.class, String.class, Integer.class);
        Student o = (Student) constructor.newInstance("windy", "男", 18);
        out.println(o.getAge());
    }

    @Test
    public void test01() throws Exception {
        Class<?> studentClazz = Class.forName("com.example.demo.bizhan.reflect.Student");
        Constructor<?>[] constructors = studentClazz.getConstructors();
        for (Constructor<?> constructor : constructors) {
            Class<?>[] parameterTypes = constructor.getParameterTypes();
            out.println(constructor.getName());
            for (Class<?> parameterType : parameterTypes) {
                out.println(parameterType);
            }
        }
    }
}
